package ui;

import java.awt.Rectangle;

import javax.swing.JFrame;

import core.ReceiveMsg;

import dto.Message;

public class UIManager extends JFrame implements Runnable{
	
	public void run() {
		
	}
	
	///
	/// 属性设置
	///
	private final static String TITLE = "NinTalk"; 	// 标题
	private final static Rectangle MAIN_WINDOW_SIZE	// 窗口大小
		= new Rectangle(100, 200, 415, 431);
	
	// 控件
	public LoginWindow loginWindow = new LoginWindow(this);
	public MainWindow mainWindow = new MainWindow(this);
	public ConfigWindow configWindow = new ConfigWindow(this);
	
	
	/**
	 * 设置主面板
	 * @throws Exception
	 */
	public UIManager() {
		
		// 基本参数
		this.setTitle(TITLE);
		this.setBounds(MAIN_WINDOW_SIZE);
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
		this.getContentPane().setLayout(null);
		this.setLocale(java.util.Locale.getDefault());
		this.setResizable(false);
		this.setLayout(null);
		
		this.getContentPane().add(loginWindow);
		loginWindow.setVisible(true);
		
		this.getContentPane().add(mainWindow);
		mainWindow.setVisible(false);
		
		this.getContentPane().add(configWindow);
		configWindow.setVisible(false);
		
		this.validate();
		this.setVisible(true);
		
		//持续接受消息
		Message msg = null;
		ReceiveMsg rcvMsg = new ReceiveMsg();
		while (true) {
			if (msg == null ) {
				msg = rcvMsg.receive();
			} else {
				String s = msg.getContent();
				mainWindow.textArea_Msg.append(s + "\n");
				msg = null;
			}
		}
		
	}
}
